package com.dferreira.axil.data;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.event.Observes;
import javax.enterprise.event.Reception;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;

import com.dferreira.axil.model.Cliente;

@RequestScoped
public class ListaDeClientes {

    @Inject
    private RepositorioDeClientes repositorioDeClientes;

    private List<Cliente> clientes;

    @Produces
    @Named
    public List<Cliente> getClientes() {
        return clientes;
    }

    public void quandoAlterarListaDeClientes(@Observes(notifyObserver = Reception.IF_EXISTS) final Cliente cliente) {
    	recuperarClientes();
    }

    @PostConstruct
    public void recuperarClientes() {
        clientes = repositorioDeClientes.findAllOrderedByName();
    }
}
